﻿using System;

namespace ReadyApps.Common.Exceptions
{
    /// <summary>
    /// Represents the error that occurs when a required control is not found in
    /// a template.
    /// </summary>
    public class MissingControlException : Exception
    {
        /// <summary>
        /// Initializes a new <see cref="MissingControlException"/> with control ID
        /// optionally the type and location.
        /// </summary>
        /// <param name="controlID">The control ID that is required.</param>
        /// <param name="controlType">The type of the control that was not found.</param>
        /// <param name="location">The template name that was searched for the control.</param>
        public MissingControlException(string controlID, Type controlType = null, string location = null)
            : base(string.Format("A control with ID '{0}'{1} was not found{2}",
                controlID,
                controlType != null ? " of type '" + controlType.ToString() + "'" : string.Empty,
                string.IsNullOrEmpty(location) ? string.Empty : " in the " + location)) { }
    }
}
